home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / hardware / fastkb / ukeyb.pas < prev    next >
Pascal/Delphi Source File  |  1994-11-28  |  3KB  |  150 lines

  1. Unit UKeyb;
  2.  
  3. (***********************************************************************
  4.  
  5.  Fast! Keyboard handler.
  6.  
  7.  Written by:
  8.  
  9.  Francesco E. Carucci
  10.  Anarchy's Art
  11.  
  12.  s75926@galileo.polito.it
  13.  
  14.  ***********************************************************************)
  15.  
  16. interface
  17.  
  18. const ESC_KEY    = 1;
  19.  
  20.       UP_KEY     = 72;
  21.       DOWN_KEY   = 80;
  22.       LEFT_KEY   = 75;
  23.       RIGHT_KEY  = 77;
  24.  
  25.       INS_KEY    = 82;
  26.       DEL_KEY    = 83;
  27.       HOME_KEY   = 71;
  28.       END_KEY    = 79;
  29.       PGUP_KEY   = 73;
  30.       PGDN_KEY   = 81;
  31.  
  32.       CTRL_KEY   = 29;
  33.       ALT_KEY    = 56;
  34.       LSHIFT_KEY = 42;
  35.       RSHIFT_KEY = 56;
  36.  
  37.       F1_KEY     = 59;
  38.       F2_KEY     = 60;
  39.       F3_KEY     = 61;
  40.       F4_KEY     = 62;
  41.       F5_KEY     = 63;
  42.       F6_KEY     = 64;
  43.       F7_KEY     = 65;
  44.       F8_KEY     = 66;
  45.       F9_KEY     = 67;
  46.       F10_KEY    = 68;
  47.       F11_KEY    = 87;
  48.       F12_KEY    = 88;
  49.  
  50.       A_KEY      = 30;
  51.       B_KEY      = 48;
  52.       C_KEY      = 46;
  53.       D_KEY      = 32;
  54.       E_KEY      = 18;
  55.       F_KEY      = 33;
  56.       G_KEY      = 34;
  57.       H_KEY      = 35;
  58.       I_KEY      = 23;
  59.       J_KEY      = 36;
  60.       K_KEY      = 37;
  61.       L_KEY      = 38;
  62.       M_KEY      = 50;
  63.       N_KEY      = 49;
  64.       O_KEY      = 24;
  65.       P_KEY      = 25;
  66.       Q_KEY      = 16;
  67.       R_KEY      = 19;
  68.       S_KEY      = 31;
  69.       T_KEY      = 20;
  70.       U_KEY      = 22;
  71.       V_KEY      = 47;
  72.       X_KEY      = 45;
  73.       Y_KEY      = 21;
  74.       Z_KEY      = 44;
  75.       A1_KEY     = 2;
  76.       A2_KEY     = 3;
  77.       A3_KEY     = 4;
  78.       A4_KEY     = 5;
  79.       A5_KEY     = 6;
  80.       A6_KEY     = 7;
  81.       A7_KEY     = 8;
  82.       A8_KEY     = 9;
  83.       A9_KEY     = 10;
  84.       A0_KEY     = 11;
  85.  
  86. var Pressed: array[0..255] of boolean;
  87.  
  88. procedure InstallKeybHandler;
  89. procedure RestoreKeybHandler;
  90.  
  91. function IsPressed(AKey: byte): boolean;
  92. function IsReleased(AKey: byte): boolean;
  93.  
  94. implementation
  95.  
  96. Uses Dos;
  97.  
  98. var SaveInt09 : Pointer;
  99.  
  100. procedure KeybHandler; interrupt;
  101. begin
  102.   asm
  103.     xor ax, ax
  104.     in al, 60h
  105.  
  106.     mov di, ax
  107.     and di, 0FF7Fh
  108.     mov bx, 7
  109.   end;
  110.  
  111.   inline(
  112.     $0F/$A3/$D8/                 (* cf=bit 7 *)
  113.     $D6                          (* if cf=0, al=0. if cf=1, al=0FFh *)
  114.   );
  115.  
  116.   asm
  117.     not al
  118.     lea bx, Pressed
  119.     mov [bx+di], al
  120.  
  121.     mov al, 020h
  122.     out 020h, al
  123.   end;
  124. end;
  125.  
  126.  
  127. procedure InstallKeybHandler;
  128. begin
  129.   GetIntVec($9,SaveInt09);
  130.   SetIntVec($9,@KeybHandler);
  131. end;
  132.  
  133. procedure RestoreKeybHandler;
  134. begin
  135.   SetIntVec($9, SaveInt09);
  136. end;
  137.  
  138. function IsPressed(AKey: byte): boolean;
  139. begin
  140.   IsPressed:=Pressed[AKey];
  141. end;
  142.  
  143. function IsReleased(AKey: byte): boolean;
  144. begin
  145.   IsReleased:=Not Pressed[AKey];
  146. end;
  147.  
  148. begin
  149.   FillChar(Pressed, 256, 0);
  150. end.